
/**
 * 动态的引入Css
 * 
 * @return {}
 */

function getContextPath() {
	var path = document.location.pathname.substr(1);
	path = "/" + path.substr(0, path.indexOf("/"));
	return path;
}
var conextPath = getContextPath();
function getFullUrl(url) {
	if (url.indexOf("../") == 0) {
		url = conextPath + url.substring(2);
	} else {
		if (url.indexOf("/") != 0) {
			url = "/" + conextPath + url;
		} else {
			if (url.indexOf(conextPath) != 0) {
				url = conextPath + url;
			}
		}
	}
	return url;
}
// 记录引入过的Css变量
var impCssRec = new Object();
function importCSS(c) { // c 是Css的路
	c = getFullUrl(c);
	if (typeof impCssRec[c] != "undefined") {
		return;
	}
	var link = document.createElement("link");
	link.rel = "stylesheet";
	link.rev = "stylesheet";
	link.type = "text/css";
	link.media = "screen";
	link.href = c;
	document.getElementsByTagName("head")[0].appendChild(link);
	impCssRec[c] = true;
}
// 记录引入过的Js变量
var impJsRec = new Object();
function importJs(url) { // url 是js的路
	url = getFullUrl(url);
	if (typeof impJsRec[url] != "undefined") {
		return;
	}
	var ajaxResut = null;
	Ext.Ajax.request({
				method : 'GET',
				disableCaching : false,
				// utf-8 编码 ,
				async : true,// 同步请求数据
				url : url,
				success : function(response) {
					ajaxResut = response.responseText;
					if (window.execScript) {
						try {
							window.execScript(ajaxResut);// 执行动态加载
							impJsRec[url] = true;// 记录到记录器中
						} catch (err) {
						}
					} else {
						eval.call(window, ajaxResut);// 执行动态加载
						impJsRec[url] = true;// 记录到记录器中
					}
					console.debug("动态加载：" + impJsRec);
				}
			});
}

// 实例化外部的Js对象
var initObjectRec = new Object();

function instanceJsObj(url) {
	url = getFullUrl(url);
	if (typeof initObjectRec[url] != "undefined") {
		return initObjectRec[url];
	}

	Ext.Ajax.request({
				method : 'GET',
				disableCaching : false,
				// utf-8 编码 ,
				async : true,// 同步请求数据
				url : url,
				success : callback
			});
	function callback(response) {
		var ajaxResult = response.responseText;
		if (console) {
			console.debug(ajaxResult);
		}
		var newobj = eval(ajaxResult);// 执行动态加载
		initObjectRec[url] = newobj;// 记录到记录器中
	}
	return initObjectRec[url];
}
